home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FPGAWKII.ZIP / PARITY.PDS < prev    next >
Text File  |  1994-10-05  |  7KB  |  169 lines

  1. ;---------------------------------------------------------
  2. ; This PLDASM file demonstrates hierarchical design and
  3. ; the definition of modules using a parity detector
  4. ; example.
  5. ;---------------------------------------------------------
  6. TITLE   parity detector 
  7.  
  8.  
  9. ;*-- beginning of 2-bit parity detector module -----------
  10. ; Our first module: a 2-bit parity detector (that's an
  11. ; XOR gate, guys).  The DEFMOD keyword starts the module
  12. ; definition.  This is followed by the name of the module
  13. ; (par2) and a parenthesized list of inputs and outputs.
  14. ;---------------------------------------------------------
  15. DEFMOD par2 ( b[0:1], odd )
  16.  
  17. ;---------------------------------------------------------
  18. ; Next comes the CHIP keyword, but for modules you don't
  19. ; want to specify a particular chip type.  Instead, use
  20. ; "Intel_arch" as a kind of generic type of chip.
  21. ;---------------------------------------------------------
  22. CHIP    par2    Intel_arch
  23.  
  24. ;---------------------------------------------------------
  25. ; Descriptions of the module inputs and outputs come next.
  26. ; You use the PIN statement, but DON'T ASSIGN PIN NUMBERS!
  27. ; That's because you are just defining the module right
  28. ; now and it has no specific location in the chip.  The
  29. ; binding of our inputs and outputs to the physical pins
  30. ; only occurs later when this module is instantiated.
  31. ;---------------------------------------------------------
  32. PIN     b[0:1]    ;* this is the 2-bit binary number
  33. PIN     odd       ;* output is high if the parity is odd
  34.  
  35. EQUATIONS
  36.     odd = b0 :+: b1    ;* just an XOR gate!
  37.  
  38. ;---------------------------------------------------------
  39. ; The ENDMOD keyword ends the definition of the 2-bit
  40. ; parity detector module.
  41. ;---------------------------------------------------------
  42. ENDMOD
  43. ;*-- end of 2-bit parity detector module -----------------
  44.  
  45.  
  46. ;*-- beginning of 4-bit parity detector module -----------
  47. ; Now start defining the 4-bit parity detector module.
  48. ; This module uses two of the 2-bit parity detector
  49. ; modules to do its job.
  50. ;---------------------------------------------------------
  51. DEFMOD par4( b[0:3], odd )
  52.  
  53. CHIP    par4    Intel_arch
  54.  
  55. PIN     b[0:3]  ;* 4-bit binary input for parity check
  56. PIN     odd     ;* odd is 1 if the 4-bit input is odd par.
  57.  
  58. ; The following pins act like temporary variables.
  59. PIN     n[0:1]  ;* these two pins are used to hold the
  60.         ;* parity of the lower and upper 2-bit
  61.         ;* fields, respectively.
  62.  
  63. ;---------------------------------------------------------
  64. ; Here is where the 2-bit parity detectors are used.
  65. ; These calls to the 2-bit detectors must come AFTER the
  66. ; inputs and outputs for the current module are declared
  67. ; because you are going to hook these I/O pins to the I/O
  68. ; of the 2-bit detector sub-modules.  The MODULE keyword
  69. ; indicates that you are going to use a sub-module.
  70. ; This keyword is followed by the name of the sub-module
  71. ; you want to use.  This is followed by a parenthesized
  72. ; list that shows how I/O pins for the sub-module are
  73. ; hooked to the I/O pins of the current module.
  74. ;---------------------------------------------------------
  75.  
  76. ; This sub-module receives the least significant 2 bits of
  77. ; the 4-bit input and stores their parity on the n0 pin.
  78. MODULE par2( b[0:1]=b[0:1], odd=n0 )
  79.  
  80. ; This sub-module receives the most significant 2 bits of
  81. ; the 4-bit input and stores their parity on the n1 pin. 
  82. MODULE par2( b[0:1]=b[2:3], odd=n1 )
  83.  
  84. ; This last sub-module takes the output of the previous
  85. ; sub-modules and XORs them to generate the parity for
  86. ; the entire 4-bit word.  You can use the par2
  87. ; module for this since it's just an XOR gate anyway.
  88. MODULE par2( b0=n0, b1=n1, odd=odd )
  89.  
  90. ENDMOD
  91. ;*-- end of the 4-bit parity detector module -------------
  92.  
  93. ;*-- beginning of 8-bit parity detector module -----------
  94. ; Now an 8-bit parity detector is built from two 4-bit
  95. ; parity detectors.
  96. ;---------------------------------------------------------
  97. DEFMOD par8( b[0:7], odd )
  98.  
  99. CHIP    par8    Intel_arch
  100.  
  101. PIN     b[0:7]  ;* 8 bits of data to check parity on
  102. PIN     odd     ;* the parity output -- high if odd parity
  103. PIN     n[0:1]  ;* pins for holding the parity of the
  104.         ;* upper and lower 4-bit sections
  105.  
  106. ; compute parity of lower 4 bits
  107. MODULE par4( b[0:3]=b[0:3], odd=n0 )
  108. ; compute parity of upper 4 bits
  109. MODULE par4( b[0:3]=b[4:7], odd=n1 )
  110. ; combine the upper and lower parities
  111. MODULE par2( b0=n0, b1=n1, odd=odd )
  112.  
  113. ENDMOD
  114. ;*-- end of 8-bit parity detector module -----------------
  115.  
  116.  
  117. ;*---------------------------------------------------------
  118. ;* Call the 8-bit parity detector module and hook it to
  119. ;* the actual inputs and outputs of the FPGA.
  120. ;*---------------------------------------------------------
  121.  
  122. CHIP    parity    NFX780_84  ; use the FPGA now!!
  123.  
  124. PIN   [47:51]   in[0:4]      ; parity detector inputs
  125. PIN   [77:78]   in[5:6]      ; parity detector inputs
  126. PIN   34        odd_parity   ; parity detector output
  127.  
  128. ; Now call the 8-bit parity detector but only use
  129. ; seven bits of it.  Set the most-significant bit to 0.
  130. MODULE par8( b[0:6]=in[0:6], b7=GND, odd=odd_parity )
  131.  
  132.  
  133.  
  134. ;---------------------------------------------------------
  135. ; Now do a simulation to make sure everything is OK.  You
  136. ; really don't want to type in all 128 possible inputs,
  137. ; so you can just let the simulator handle it
  138. ; as you'll see below.
  139. ;---------------------------------------------------------
  140. SIMULATION
  141.  
  142.     ; First, define a VECTOR called "number" from the 7
  143.     ; input bits.  Start with a [ and then list the
  144.     ; inputs you want in the vector (most significant
  145.     ; first, least significant last) after which you end
  146.     ; the declaration with a ].  Don't forget the
  147.     ; commas between the entries in the vector list!
  148.     VECTOR number := [in6,in5,in4,in3,in2,in1,in0]
  149.  
  150.     TRACE_ON number odd_parity
  151.  
  152.     ; Now, you can iterate through all 127 input
  153.     ; combinations using the variable i as a loop
  154.     ; counter.  Note that you are using hexadecimal
  155.     ; notation for the numbers.  You can use decimal,
  156.     ; octal, or binary as well.
  157.     FOR i:=0 TO 127 DO
  158.     BEGIN
  159.  
  160.     ; For each simulation step, assign the value of
  161.     ; the loop counter to the input vector using the
  162.     ; SETF operation.  The output of the circuit will
  163.     ; be simulated using this input, so you can check
  164.     ; all the possible input cases using
  165.     ; only a few lines of code.
  166.     SETF number := i
  167.  
  168.     END
  169.